Soru & Cevap

Kamerada görüntü alma

11.07.2014 - 03:19

Uygulamam çalışırken kamerada görüntüyü alıp kaydetmek istiyorum. Bunu nasıl yapabilirim ?

9 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-103767-1491764696.jpg
elfaybkeasln
13.07.2017 - 09:06

activity_main.xml


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" android:padding="16dp" tools:context="example.elif.com.kameradanresimcekme.MainActivity">

<ImageView android:id="@+id/imageView"

android:layout_width="400dp"

android:layout_height="400dp"

android:layout_gravity="center"/>

<Button android:id="@+id/btn"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Kamerayı Aç"/>

</LinearLayout>

 

MainActivity.java

 

import android.content.Intent;

import android.graphics.Bitmap;

import android.os.Bundle;

import android.provider.MediaStore;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.Button;

import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

Button btn;

ImageView imageView;

static final int IMAGE_CAPTURE=1453;

@Override protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

getController();

setClickForView(); }

public void getController(){

btn=(Button)findViewById(R.id.btn);

imageView= (ImageView) findViewById(R.id.imageView);

}

public void setClickForView(){

btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

takeImage();

}

});     }

private void takeImage(){

Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if(intent.resolveActivity(getPackageManager())!=null){

 startActivityForResult(intent,IMAGE_CAPTURE); }

} /

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resultCode==RESULT_OK){ if(requestCode==IMAGE_CAPTURE){

 Bundle extras=data.getExtras();

Bitmap imageBitmap=(Bitmap) extras.get("data");

imageView.setImageBitmap(imageBitmap); }

} }

}